import demo10.Singleton;

import java.io.*;


public class Client {
    public static void main(String[] args) throws Exception {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = (Singleton) s1.clone();
        System.out.println(s1 == s2);
    }

    // 从文件中读取对象
    public static void readObjectFromFile() throws Exception {
        // 创建对象输入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(".\\a.txt"));
        // 读取对象
        Singleton instance = (Singleton) ois.readObject();
        System.out.println(instance);
        // 释放资源
        ois.close();
    }

    // 向文件中写入对象
    public static void writeObject2File() throws Exception {
        // 获取单例对象
        Singleton instance = Singleton.getInstance();
        // 创建对象输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(".\\a.txt"));
        // 写对象
        oos.writeObject(instance);
        // 释放资源
        oos.close();
    }
}